const { Admin } = require('./db');

const built_in_username = 'admin';
const built_in_password = '123456';

const createSuperAdmin = async () => {
    try {
        const result = await Admin.findOne({
            username: built_in_username,
            password: built_in_password,
            role: 0
        })
    
        if (result) {
            console.log(`超级管理员已存在，账号为:${built_in_username}，密码为:${built_in_password}`);
        } else {
            await Admin.create({
                username: built_in_username,
                password: built_in_password,
                role: 0
            })
    
            console.log(`超级管理员已创建，账号为:${built_in_username}，密码为:${built_in_password}`);
        }
    } catch (error) {
        console.log('内置超级管理员失败', error);
    }
};

module.exports = {
    createSuperAdmin
}